const express = require("express");
const morgan = require("morgan");
const cors = require("cors");
const router = require("./router/index.js");
const errorHandler = require("./middleware/error-handler.js");
require("./model");

const app = express();
const PORT = process.env.PORT || 3000; // mac /linux PORT = 5000 nodemon app.js

app.use(morgan("dev"));
app.use(express.json());
app.use(express.urlencoded());
app.use(cors());

// 挂载路由
app.use("/api", router);

// 挂载统一处理服务端错误的中间件
app.use(errorHandler());

app.listen(PORT, () => {
  console.log("server is running at http://localhost:3000/");
});
